package MCQReaderInterface;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.JLabel;
import javax.swing.tree.TreeNode;

import MCQReaderModel.BitField;
import MCQReaderModel.Case;
import MCQReaderModel.Radio;
import MCQReaderModel.TextZone;
import MCQReaderModel.Zone;

public class MCQReaderSelection extends JLabel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MCQReaderSelection() {

	}

	protected void paintComponent(Graphics g) {
		TreeNode node = MainInterface.thisIsIt.getLeftFrame().getTree()
				.currentNodePage();
		drawSelections(node, g);
	}

	void drawSelections(TreeNode node, Graphics g) {
		for (int i = 0; i < node.getChildCount(); i++) {
			if (MainInterface.thisIsIt.getLeftFrame().getTree().selected == node
					.getChildAt(i))
				((Graphics2D) g).setStroke(new BasicStroke(2));
			if (node.getChildAt(i).isLeaf()) {
				if (node.getChildAt(i) instanceof Zone) {
					Rectangle rect = ((Zone) node.getChildAt(i)).getRectangle();
					if (node.getChildAt(i) instanceof Radio) {
						g.setColor(Color.red);
						g.drawRect(rect.x, rect.y, rect.width, rect.height);
					} else if (node.getChildAt(i) instanceof Case) {
						g.setColor(Color.blue);
						g.drawRect(rect.x, rect.y, rect.width, rect.height);
					} else if (node.getChildAt(i) instanceof BitField) {
						g.setColor(Color.green);
						g.drawRect(rect.x, rect.y, rect.width, rect.height);
					} else if (node.getChildAt(i) instanceof TextZone) {
						g.setColor(Color.yellow);
						g.drawRect(rect.x, rect.y, rect.width, rect.height);
					}
				}
			} else
				drawSelections(node.getChildAt(i), g);
			if (MainInterface.thisIsIt.getLeftFrame().getTree().selected == node
					.getChildAt(i))
				((Graphics2D) g).setStroke(new BasicStroke(1));
		}
	}

}
